package com.zhou.yygh.hosp.controller.api;

import com.zhou.yygh.common.result.Result;
import com.zhou.yygh.hosp.service.DepartmentService;
import com.zhou.yygh.hosp.service.HospitalService;
import com.zhou.yygh.hosp.service.HospitalSetService;
import com.zhou.yygh.hosp.service.ScheduleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.bouncycastle.pqc.crypto.newhope.NHOtherInfoGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zhou.hospital.model.hosp.Hospital;
import zhou.hospital.model.hosp.Schedule;
import zhou.hospital.vo.hosp.DepartmentVo;
import zhou.hospital.vo.hosp.HospitalQueryVo;
import zhou.hospital.vo.hosp.ScheduleOrderVo;
import zhou.hospital.vo.order.SignInfoVo;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/hosp/hospital")
public class HostApiController {
    @Autowired
    private HospitalService hospitalService;
    @Autowired
    private DepartmentService departmentService;
    @Autowired
    private ScheduleService scheduleService;
    @Autowired
    private HospitalSetService hospitalSetService;

    @GetMapping("/findHospList/{page}/{limit}")
    @ApiOperation("查询医院列表")
    public Result findHospList(@PathVariable Integer page,
                               @PathVariable Integer limit,
                               HospitalQueryVo hospitalQueryVo) {
        Page<Hospital> hospitalPage = hospitalService.selectHospPage(page, limit, hospitalQueryVo);


        return Result.ok(hospitalPage);
    }

    @GetMapping("/findByHosName/{hosname}")
    @ApiOperation("根据医院名称查询")
    public Result findByHosName(@PathVariable String hosname) {

        List<Hospital> list = hospitalService.findHosByName(hosname);
        return Result.ok(list);
    }


    @ApiOperation(value = "根据hoscode获取医院科室")
    @GetMapping("/department/{hoscode}")
    public Result findByHoscode(@PathVariable String hoscode) {
        List<DepartmentVo> deptTree = departmentService.getDeptTree(hoscode);
        return Result.ok(deptTree);

    }

    @ApiOperation(value = "根据hoscode获取医院预约挂号详情")
    @GetMapping("/{hoscode}")
    public Result findHospitalDetail(@PathVariable String hoscode) {
        Map<String, Object> map = hospitalService.items(hoscode);
        return Result.ok(map);

    }

    @ApiOperation(value = "获取可预约排班数据")
    @GetMapping("/auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingSchedule(@PathVariable Integer page,
                                     @PathVariable Integer limit,
                                     @PathVariable String hoscode,
                                     @PathVariable String depcode) {
        Map<String, Object> map = scheduleService.getBookingSchedule(page, limit, hoscode, depcode);
        return Result.ok(map);
    }


    @ApiOperation(value = "获取排班数据")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(
            @PathVariable String hoscode,
            @PathVariable String depcode,
            @PathVariable String workDate) {
        return Result.ok(scheduleService.getDetailSchedule(hoscode, depcode, workDate));
    }

    @ApiOperation(value = "根据排班id获取排班数据")
    @GetMapping("/getSchedule/{scheduleId}")
    public Result getSchedule(@PathVariable String scheduleId) {
        Schedule schedule = scheduleService.getById(scheduleId);
        return Result.ok(schedule);
    }

    @ApiOperation(value = "根据排班id获取预约下单数据")
    @GetMapping("/inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(@PathVariable String scheduleId) {
        ScheduleOrderVo scheduleOrderVo = scheduleService.getScheduleOrderVo(scheduleId);
        return scheduleOrderVo;
    }

    @ApiOperation(value = "获取医院签名信息")
    @GetMapping("/inner/getSignInfoVo/{hoscode}")
    public SignInfoVo getSignInfoVo(
            @PathVariable("hoscode") String hoscode) {
       SignInfoVo signInfoVo =hospitalSetService.getSignInfoVo(hoscode);
        return signInfoVo;
    }
}
